﻿#region File Description
//-----------------------------------------------------------------------------
// OptionsMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
#endregion

namespace Kosmos
{
    /// <summary>
    /// The options screen is brought up over the top of the main menu
    /// screen, and gives the user a chance to configure the game
    /// in various hopefully useful ways.
    /// </summary>
    class OptionsMenuScreen : MenuScreen
    {
        #region Fields

        MenuEntry fullScreenMenuEntry;
        MenuEntry musicMenuEntry;

        static bool fullScreen = Program.game.GraphicsDeviceManager.IsFullScreen;
        static bool music = true;

        #endregion

        #region Getters and Setters

        public bool Music
        {
            get { return music; }
        }

        public bool FullScreen
        {
            get { return fullScreen; }
            set { fullScreen = value; }
        }

        #endregion

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        public OptionsMenuScreen()
            : base("Options",false)
        {
            // Create our menu entries.
            fullScreenMenuEntry = new MenuEntry(string.Empty);
            musicMenuEntry = new MenuEntry(string.Empty);

            SetMenuEntryText();

            MenuEntry backMenuEntry = new MenuEntry("Back");

            // Hook up menu event handlers.
            fullScreenMenuEntry.Selected += FullScreenEntrySelected;
            musicMenuEntry.Selected += MusicMenuEntrySelected;
            backMenuEntry.Selected += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(musicMenuEntry);
            MenuEntries.Add(fullScreenMenuEntry);
            MenuEntries.Add(backMenuEntry);
        }


        /// <summary>
        /// Fills in the latest values for the options screen menu text.
        /// </summary>
        void SetMenuEntryText()
        {
            musicMenuEntry.Text = "Music: " + (music ? "on" : "off");
            fullScreenMenuEntry.Text = "Fullscreen Mode: " + (FullScreen ? "on" : "off");
        }


        #endregion

        #region Handle Input

        /// <summary>
        /// Event handler for toggling the activation of the music.
        /// </summary>
        void MusicMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            music = !music;

            SetMenuEntryText();
            /*
            if (music)
                Program.game.AudioManager.playMusic();
            else
                Program.game.AudioManager.stop();
             */
        }

        /// <summary>
        /// Event handler for toggling the activation of the music.
        /// </summary>
        void FullScreenEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            FullScreen = !FullScreen;

            SetMenuEntryText();

            Program.game.GraphicsDeviceManager.ToggleFullScreen();
            
        }

        #endregion
    }
}
